package com.manor.main.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.manor.common.utils.KLog
import com.manor.common.utils.RouteUtil
import com.manor.main.R
import com.mob.videosdk.DrawVideoFragment
import com.mob.videosdk.VideoSdk

/**
 * 短视频
 *
 * @date  2021/3/25  13:57
 * @version 1.0
 */
@Route(path = RouteUtil.PATH_S_VIDEO)
class SVideoFragment : Fragment() {
    private var mDrawVideoFragment: DrawVideoFragment? = null
    private var isFirstLoad = true

    companion object {
        fun newInstance(): SVideoFragment {
            return SVideoFragment()
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val v: View? = inflater.inflate(R.layout.fragment_s_video, container, false)
        return v
    }

    override fun onResume() {
        super.onResume()
        if (mDrawVideoFragment == null)
            initView()
        KLog.e("SV#onResume", "----onResume----")
    }


    private fun initView() {
        mDrawVideoFragment = DrawVideoFragment.newInstance()
        mDrawVideoFragment?.let {
            childFragmentManager?.beginTransaction()
                    ?.replace(R.id.rootLay, it)
                    ?.commitNowAllowingStateLoss()
        }
        mDrawVideoFragment?.setVideoListener(object : VideoSdk.VideoListener {
            override fun onVideoShow(p0: String?, p1: Int) {
                KLog.e("SV#onVideoShow", "--------")
            }

            override fun onVideoStart(p0: String?, p1: Int) {
                KLog.e("SV#onVideoStart", "--------")
                if (isFirstLoad) {

                    mDrawVideoFragment?.onStop()
                    isFirstLoad = false
                }

            }

            override fun onVideoPause(p0: String?, p1: Int) {
            }

            override fun onVideoResume(p0: String?, p1: Int) {
                KLog.e("SV#onVideoResume", "--------")
            }

            override fun onVideoComplete(p0: String?, p1: Int) {
                KLog.e("SV#onVideoComplete", "--------")
            }

            override fun onVideoError(p0: String?, p1: Int) {
                KLog.e("SV#onVideoError", "--------")
            }

        })
        mDrawVideoFragment?.setOnLikeClickListener(object : VideoSdk.OnLikeClickListener {
            override fun onLikeClick(p0: String?, p1: Int, p2: Boolean): Boolean {
                return false
            }
        })
        mDrawVideoFragment?.setOnShareClickListener(object : VideoSdk.OnShareClickListener {
            override fun onShareClick(p0: String?, p1: Int, p2: String?, p3: String?, p4: String?): Boolean {
                return false
            }
        })
        mDrawVideoFragment?.setProgressListener(object : VideoSdk.ProgressListener {
            override fun onProgressUpdate(p0: String?, p1: Int, p2: Int, p3: Int) {

            }
        })
    }

    override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)
        mDrawVideoFragment?.userVisibleHint = isVisibleToUser
    }


    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        mDrawVideoFragment?.onHiddenChanged(hidden)
    }


}


/*

class SVideoFragment : DrawVideoFragment() {

    companion object {
        fun newInstance(): SVideoFragment {
            return SVideoFragment()
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        DrawVideoFragment.newInstance()
        setVideoListener(object : VideoSdk.VideoListener {
            override fun onVideoShow(p0: String?, p1: Int) {
            }

            override fun onVideoStart(p0: String?, p1: Int) {
            }

            override fun onVideoPause(p0: String?, p1: Int) {
            }

            override fun onVideoResume(p0: String?, p1: Int) {
            }

            override fun onVideoComplete(p0: String?, p1: Int) {
            }

            override fun onVideoError(p0: String?, p1: Int) {
            }

        })
        setOnLikeClickListener(object : VideoSdk.OnLikeClickListener {
            override fun onLikeClick(p0: String?, p1: Int, p2: Boolean): Boolean {
                return false
            }
        })
        setOnShareClickListener(object : VideoSdk.OnShareClickListener {
            override fun onShareClick(p0: String?, p1: Int, p2: String?, p3: String?, p4: String?): Boolean {
                return false
            }
        })
        setProgressListener(object : VideoSdk.ProgressListener {
            override fun onProgressUpdate(p0: String?, p1: Int, p2: Int, p3: Int) {

            }
        })

    }


    override fun onPause() {
        super.onPause()
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
    }


}


 */


















